<template>

	<!-- 数据列表 -->
	<mescroll-uni @init="mescrollInit" @down="downCallback" @up="upCallback" height="100%">
		<view class="page-box">
			<view class="order" v-for="(res, index) in list" :key="res.id">
				<template v-if="i===0">
					<bb-member :info="res"></bb-member>
				</template>
				<template v-else>
					<bb-demand :info="res" @change="downCallback"></bb-demand>
				</template>
			</view>
		</view>
	</mescroll-uni>
</template>

<script>
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	import MescrollMoreItemMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mixins/mescroll-more-item.js";
	export default {
		mixins: [MescrollMixin, MescrollMoreItemMixin],
		data() {
			return {
				downOption: {
					auto: false
				},
				upOption: {
					auto: false,
				},
				list: [] //列表数据
			}
		},
		props: {
			i: Number,
			index: {
				type: Number,
				default () {
					return 0
				}
			},
			tabs: {
				type: Array,
				default () {
					return []
				}
			},
			height: [Number, String] // mescroll的高度
		},
		methods: {
			/*下拉刷新的回调 */
			downCallback() {
				this.mescroll.resetUpScroll()
			},
			/*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
			upCallback(page) {
				this.queryPowers(page)
			},
			queryPowers(page) {
				//联网加载数据
				const type = this.tabs[this.i].type
				const location = uni.getStorageSync('userLocation')
				this.$u.api.visitList({
					page: page.num,
					limit: page.size,
					type,
					location
				}).then(res => {
					//联网成功的回调,隐藏下拉刷新和上拉加载的状态;
					this.mescroll.endSuccess(res.length);
					//设置列表数据
					if (page.num == 1) this.list = []; //如果是第一页需手动制空列表
					this.list = this.list.concat(res); //追加新数据
				}).catch(() => {
					//联网失败, 结束加载
					this.mescroll.endErr();
				})
			},

		}
	}
</script>

<style scoped>
	.page-box {
		padding: 30rpx;
	}
</style>